<template>
  <div @click="openFileInput">
    <input type="file" ref="fileInput" style="display: none" @change="handleChange">
    <slot />
  </div>
</template>

<script>
import { initCOS } from '../../utils/upload'
export default {
  name: 'index',
  data () {
    return {
      selectedFile: null
    };
  },
  methods: {
    openFileInput () {
      uni.chooseImage({
        count: 1,
        success: async (res) => {
          this.selectedFile = res.tempFiles[0];
          console.log("🚀 ~ file: index.vue:23 ~ openFileInput ~ this.selectedFile:", this.selectedFile)
          const pic = await initCOS(this.selectedFile, '', true, '', true);
          this.$emit('url',pic)
          console.log("🚀 ~ file: index.vue:25 ~ success: ~ pic:", pic)
        }
      });
    },
  }
};
</script>

<style scoped>
</style>